#include "stdafx.h"
#include "Main.h"
Player::Player()
{
	HealthPoints=100;
}
void Player::create(Game::ObjParams &obj)
{
	obj.phys(true, "obj/chr/human/0.phys");
	obj.matrix.pos=Vec(3,2,0);
	obj.matrix.scale(3);
	super::create(obj);
}
Bool Player::Alive() { return HealthPoints>0; }
Bool Player::update()
{
   if(action)
   {
      if(Kb.b(KB_W) || Kb.b(KB_S) || Kb.b(KB_A) || Kb.b(KB_D) || Kb.b(KB_Q) || Kb.b(KB_E))actionBreak();
   }

   if(!action)
   {
      input.turn.x=Kb.b(KB_Q)-Kb.b(KB_E);
      input.move.x=Kb.b(KB_D)-Kb.b(KB_A);
      input.move.z=Kb.b(KB_W)-Kb.b(KB_S);
      input.move.y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);
      input.crouch= Kb.b (KB_LSHIFT);
      input.walk  = Kb.b (KB_LCTRL );
      input.jump  =(Kb.bp(KB_SPACE ) ? 3.5f : 0);
   }
      Flt max=DegToRad(900)*Time.d();
      angle.x-=Mid(Ms.d().x*1.7f, -max, max);
      angle.y+=Mid(Ms.d().y*1.7f, -max, max);
   return super::update();
}
void Player::camera()
{
	C OrientP &head=cskel.getPoint("head");
    Cam.setPosDir(head.pos, head.dir, head.perp); 
	Cam.updateVelocities().set();
}
UInt Player::drawPrepare()
{
   Bool hide_head=(mesh);
   if(hide_head)mesh->hide("head"); 
   UInt modes=super::drawPrepare(); 
   if(hide_head)mesh->show("head"); 
   return modes;
}
void Player::CrossHair()
{
      VI.line(Color(255,255,255,255), Color(100,100,100, 255), (0,0), (0,0)+Vec2( 0.04, 0));
      VI.line(Color(255,255,255,255), Color(100,100,100, 255), (0,0), (0,0)+Vec2(-0.04, 0));
      VI.line(Color(255,255,255,255), Color(100,100,100, 255), (0,0), (0,0)+Vec2( 0, 0.04));
      VI.line(Color(255,255,255,255), Color(100,100,100, 255), (0,0), (0,0)+Vec2( 0,-0.04));
      VI.end ();
}
void Player::Die()
{
	T.ragdollEnable();
}
void Player::RecieveDamage(Flt Damage)
{
	if(HealthPoints>0)HealthPoints-=Damage;
	if(HealthPoints<=0)HealthPoints=MaxHealthPoints,Die();
}